package com.qf.boot2204;

import com.qf.boot2204.entity.User;
import com.qf.boot2204.service.HelloService;
import com.qf.boot2204.service.TestService;
import com.qf.boot2204.util.Car;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;

/*
* springboot项目的启动类
添加了 @SpringBootApplication注解的类就是启动类;
* 约定:项日中其他所有的包，都需要在这个启动类的平级或者下级
*/
@SpringBootApplication
@EnableConfigurationProperties(Car.class)
public class Boot2204Application {
    public static void main(String[] args) {
        //启动项目
        //该方法返回的对象 就是spring 的ioc容器对象本身
        ConfigurableApplicationContext context = SpringApplication.run(Boot2204Application.class, args);
        //在ioc容器中查找指定接口类型的bean对象
        TestService test = context.getBean(TestService.class);
        System.out.println(test.test());

        HelloService hello = context.getBean(HelloService.class);
        System.out.println(hello.hello());

        HelloService hello1 = context.getBean(HelloService.class);
        System.out.println("HelloService是不是单例="+(hello==hello1));

        /*User u1 = context.getBean(User.class);*/
        User u1 =(User) context.getBean("user1");
        //User u2 = context.getBean(User.class);
        User u2 =(User) context.getBean("user2");
        System.out.println("User是不是单例="+(u1==u2));
    }

}
